/*
 *  ZanView
 *  created by qinghong
 *  2016-7-13
 */

/*
 * 定制版ZanView,需给定参数 style  zanNum
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity
} from 'react-native';

import Button from '../Button';

export default class ZanView extends Component {
    constructor(props) {
        super(props);
        const { zanNum } = this.props;
        this.state = {
            selected: false,
            zanNum: zanNum
        };
    }

    zanAction = () => {
        let selected = this.state.selected;
        var zanNum = parseInt(this.state.zanNum);
        zanNum = selected ? zanNum - 1 : zanNum + 1;

        this.setState({
            selected: !selected,
            zanNum: zanNum
        });
    };

    render() {
        const { style } = this.props;

        return (
            <View style={style}>
                <Button pressAction={this.zanAction}
                        style={{marginLeft: 10, marginRight: 5}}
                        normalImg={require('../../images/home_like.png')}
                        selectedImg={require('../../images/home_like_hl.png')}/>
                <Text style={{fontSize: 12, marginRight: 22}}>{this.state.zanNum}</Text>
            </View>
        );
    }
}
